import 'package:ninetyfour/l10n/app_localizations.dart';

import '../../models/order_list_model.dart';
import '../manger/network_utils.dart';

// 封装返回结果
class LoadOredrInfoResult {
  final bool success;
  final List<OrderArrayModel>? orderListModel;
  LoadOredrInfoResult({required this.success, this.orderListModel});
}

// 单例管理器
class OrederInfoManager {
  static final OrederInfoManager _instance = OrederInfoManager._internal();
  factory OrederInfoManager() => _instance;
  OrederInfoManager._internal();

  // 全局数据
  List<OrderArrayModel>? _orderListModel;

  // 获取全局数据方法
  List<OrderArrayModel>? get orderListModel => _orderListModel;

  // 加载分类页信息
  Future<LoadOredrInfoResult> loadInfoData({Map<String, dynamic>? body}) async {

    try {
      final response = await NetworkUtils.post(
        isChineseLocale() ? RequestCmd.orderPage : RequestCmd.orderPageen,
        body: body,
      );

      final model = OrderDataModel.fromJson(response);

      if (model.code == 200) {
        _orderListModel = model.data?.list;
        return LoadOredrInfoResult(success: true, orderListModel: model.data?.list);
      } else {
        return LoadOredrInfoResult(success: false);
      }
    } catch (e) {
      return LoadOredrInfoResult(success: false);
    }
  }
}
